<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <meta name = "format-detection" content = "telephone=no">
    <title>{:getStoreName($_GET['local_id'])}-领取礼券</title>
    <link rel="stylesheet" href="__PUBLIC__/Home/css/coupon.css?v=20170322002">
    <include file="Public/common_js"/>
</head>
<body>
<div id="ajax-couponlist" class="coupon-get-list"></div>


<div class="coupon-info-popup">
    <a href="javascript:;" class="close"></a>
    <div class="cp-body">
        <span id="curCouponTit" class="tit"></span>
        <div id="curCouponDesc" class="desc">
            正在加载中...
        </div>
    </div>
</div>
<include file="Public/bind_phone"/>
<script type="text/javascript">
    var isDetailInit = false;
    var isAjaxTake = false;
    var isAjaxDetail = false;
    function showCouponDetail(obj, e){

        if(isAjaxDetail) return;
        isAjaxDetail = true;
        var _self = $(obj);
        var cparent = _self.parents(".oneitem");
        $("#curCouponTit").html(cparent.find(".tit").html());
        $("#curCouponDesc").html("正在加载中...");
        _global.promote.popup(".coupon-info-popup", isDetailInit);
        if(!isDetailInit){
            isDetailInit = true;
        }
        var _id = cparent.attr("data-id");

        $.ajax({
            url: '/Home/NewUserCoupon/isCouponBagDetail'+getFixedExtraUrl(),
            type: 'post',
            data: { 'id': _id},
            dataType: 'json',
            success: function(rs) {
                if(rs && rs.data != null){
                    var output = "";
                    var dlen = rs.data.length;
                    for(var i = 0; i < dlen; i++){
                        output += rs.data[i] + (i == dlen - 1 ? "。" : ";<br/>");
                    }
                    $("#curCouponDesc").html(output);
                }
                isAjaxDetail = false;
            },
            error: function() {
                $("#curCouponDesc").html("加载失败!");
                isAjaxDetail = false;
            }
        });
    }
    function takeCoupon(obj, e){
        var _self = $(obj);
        if(_self.hasClass("disable")) return;
        e.preventDefault();
        _global.checkPhoner.verifyfunc = function(rs){
            if(rs){
                ajaxTakeCoupon(e, _self);
                return true;
            }else{
                return false;
            }
        };
        _global.checkPhoner.succfunc =function(){
            ajaxTakeCoupon(e, _self);
        };
        _global.checkPhoner.run(e);
    }
    function ajaxTakeCoupon(e, _self){
        if(isAjaxTake){
            return false;
        }
        isAjaxTake = true;
        var cparent = _self.parents(".oneitem");
        var _id = cparent.attr("data-id");
        $.ajax({
            url: '/Home/NewUserCoupon/getCouponBag'+getFixedExtraUrl(),
            type: 'post',
            data: { 'id': _id},
            dataType: 'json',
            success: function(rs) {
                _global.promote.alertPopup(rs.msg);
                // status 1 2 3
                if(rs.status == 3){
                    _self.removeClass('active').addClass('disable').text("已领");
                }else if(rs.status == 0){
                    _self.removeClass('active').addClass('disable').text("已抢光");
                }else if(rs.status == 1){
                    _self.removeClass('active').addClass('disable').text("过期");
                }else if(rs.status == 2){
                    _self.removeClass('active').addClass('disable').text("异常");
                }else if(rs.status == 4){
                    _self.removeClass('active').addClass('disable').text("数据异常");
                }
                isAjaxTake = false;
            },
            error: function() {
                _global.promote.alertPopup('服务器异常，请稍后重试！');
                isAjaxTake = false;
            }
        });
    }
    require(['member/couponGet']);
</script>




</body>
</html>